package top.lyjwn.todo.weinxin;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import top.lyjwn.todo.weinxin.param.WXPayParam;
import top.lyjwn.todo.weinxin.utils.SSLUilt;

/**
 * 微信支付配置
 *
 * @author luoyujie
 */
@Configuration
public class WXPayConfig implements EnvironmentAware {

    private  Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }



    @Bean
    public WXPayParam getWXPayParam()
    {
        WXPayParam wxPayParam = new WXPayParam();
        String apiKey = this.environment.getProperty("lyjwn.weinxin.mch.api-key");
        wxPayParam.setApiKey(apiKey);
        String appid = this.environment.getProperty("lyjwn.weinxin.mch.appid");
        wxPayParam.setAppid(appid);
        String id = this.environment.getProperty("lyjwn.weinxin.mch.id");
        wxPayParam.setMchId(id);
        String domain_name = this.environment.getProperty("lyjwn.weinxin.mch.domain-name");
        wxPayParam.setDomainName(domain_name);
        String auth_domain_name = this.environment.getProperty("lyjwn.weinxin.mch.auth-domain-name");
        wxPayParam.setAuthDomainName(auth_domain_name);
        String certificate = this.environment.getProperty("lyjwn.weinxin.mch.certificate");
        wxPayParam.setCertificate(certificate);
        String mch_seria_lno = this.environment.getProperty("lyjwn.weinxin.mch.mch-seria-lno");
        wxPayParam.setMchSeriaLno(mch_seria_lno);
        wxPayParam.setSslKey(SSLUilt.class.getResourceAsStream("/apiclient_cert.p12"));
        wxPayParam.setCertCode(SSLUilt.readCertFile(wxPayParam.getSslKey()));
        return wxPayParam;
    }


    /**
    @Value("${top.lyjwn.todo.weinxin.mch.certificate}")
    public static void setCERTIFICATE(String CERTIFICATE) {
        WXPayConfig.CERTIFICATE = CERTIFICATE;
    }

    @Value("${top.lyjwn.todo.weinxin.mch.mch_seria_lno}")
    public static void setMchSeriaLno(String mchSeriaLno) {
        MCH_SERIA_LNO = mchSeriaLno;
    }
     */

    /*
    @Value("${top.lyjwn.todo.weinxin.mch.apiKey}")
    public void setApiKey(String apiKey) {
        API_KEY = apiKey;
    }

    @Value("${top.lyjwn.todo.weinxin.mch.appid}")
    public void setAPPID(String APPID) {
        WXPayConfig.APPID = APPID;
    }

    @Value("${top.lyjwn.todo.weinxin.mch.id}")
    public void setMchId(String mchId) {
        MCH_ID = mchId;
    }

    @Value("${top.lyjwn.todo.weinxin.mch.domain_name}")
    public void setDomainName(String domainName) {
        DOMAIN_NAME = domainName;
    }

    @Value("${top.lyjwn.todo.weinxin.mch.auth_domain_name}")
    public void setAuthDomainName(String authDomainName) {
        AUTH_DOMAIN_NAME = authDomainName;
    }
     */
}
